package tresp.utils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import tresp.bthreads.BThread;
import tresp.bthreads.BThreadType;

/**
 * <b>BThreadManager</b>
 * 
 * <p>
 * 	This class holds references to all b-threads
 * </p>
 * 
 * @author <font color="blue">Maxim Kirilov</font>
 *
 */
public class BThreadManager {

    private static BThreadManager instance;
    
    private Map<BThreadType, BThread> allBThreads;
    
    
    public static BThreadManager getInstance(){
	
	if ( instance == null){
	    synchronized( BThreadManager.class ){
		if ( instance == null){
		    instance = new BThreadManager();
		}
	    }
	}
	return instance;
    }
    
    private BThreadManager(){
	allBThreads = new ConcurrentHashMap<BThreadType, BThread>();
    }
    
    
    public void addBthread(BThreadType bthreadType, BThread bthread){
	allBThreads.put(bthreadType, bthread);
    }
    
    public BThread getBThread(BThreadType bthreadType){
	return allBThreads.get( bthreadType );
    }
    
}
